<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> 
<!doctype html>
<html>
<head>
<meta charset="gbk" />
<title>产品列表管理</title>
<meta http-equiv="expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<link rel="stylesheet" href="../css/admin_style.css" />
<script type="text/javascript" src="../js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="../js/core/core.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/validate.js"></script>
<script type="text/javascript">
var imgpath = 'images';

//check used
function showselect(type){
	var selects = get_tags(document,'select');
	for (i=0; i<selects.length; i++) {
		selects[i].style.visibility = type;
	}
}
function checkgroupset(chars){
	if (!confirm("确定删除吗? 如果您删除了此代理组,请到站点缓存数据管理更新代理头衔缓冲!")) return false;
	window.location.href = chars;return false;
}
function get_tags(parentobj,tag){
	if (typeof parentobj.getElementsByTagName!='undefined') {
		return parentobj.getElementsByTagName(tag);
	} else if (parentobj.all && parentobj.all.tags) {
		return parentobj.all.tags(tag);
	} else {
		return null;
	}
}
//other function
function atccheck(){
	if(document.FORM.atc_title.value==''){
		alert('标题为空');
		document.FORM.atc_title.focus();
		return false;
	} else if(document.FORM.fid.value==''){
		alert('没有选择文章所属分类');
		document.FORM.fid.focus();
		return false;
	}
	_submit();
}
function level_jump(admin_file){
	var URL=document.mod.selectfid.options[document.mod.selectfid.selectedIndex].value;
	location.href=admin_file+"?adminjob=level&action=editgroup&gid="+URL;
}
function ip_jump(name){
	URL = eval('document.form1.' + name + '.options[document.form1.' + name + '.selectedIndex].value');
	location.href=URL;
}
function pwJsCheck(_this,check,tagName){
	try{
		if (typeof tagName == 'undefined') tagName = "tr";
		if (typeof check == 'undefined') {
			if (typeof _this.checked == 'boolean') {
				check = _this.checked;
			} else {
				check = false;
			}
		}
		var o = _this.parentNode;
		var i = 3;
		while(i--){
			if (o.nodeName.toLowerCase() == tagName) {
				var className =  o.className.replace(/\s?td_bgC/ig, "");
				if (check) {
					className +=' td_bgC';
				}
				o.className = className;
				break;
			} else {
				o = o.parentNode;
			}
		}
	}catch(e){}
}
//Cookies Function
function getCookie(name) {
    var start = document.cookie.indexOf(name + '=');
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start==-1) {
        return null;
    }
    var end = document.cookie.indexOf(';', len);
    if (end == -1) {
        end = document.cookie.length;
    }
    return unescape(document.cookie.substring(len,end));
}
function setCookie(name, value, expires, path, domain, secure) {
	if (!expires) {
		expires = new Date();
		expires.setTime(expires.getTime()+31536000);
	}
	document.cookie = name + '=' + escape(value) +
        ( (expires) ? ';expires=' + expires.toGMTString() : '') +
        'path=' + ( (path) ? path : '/') +
        ( (domain)  ? ';domain=' + domain : '') +
        ( (secure)  ? ';secure' : '');
}

function elementBind(type,id,stylename,csstext){
	var element = document.createElement(type);
	if (id) {
		element.id = id;
	}
	if (typeof(stylename) == 'string') {
		element.className = stylename;
	}
	if (typeof(csstext) == 'string') {
		element.style.cssText = csstext;
	}
	return element;
}
function addChild(parent,type,id,stylename,csstext){
	parent = objCheck(parent);
	var child = elementBind(type,id,stylename,csstext);
	parent.appendChild(child);
	return child;
}

function delElement(id){
	id = objCheck(id);
	id.parentNode.removeChild(id);
}
function objCheck(obj) {
	if (typeof(obj)=='string') {
		obj	= getObj(obj);
	}
	return obj;
}
document.onkeydown = function(e){
	var e = is_ie ? window.event: e;
	if ( e.keyCode==116) {
		window.location.reload();
		if (is_ie) {
			e.keyCode = 0;
       		e.cancelBubble = true;
		}
		return false;
	}
}

function openNewUrl(id,name,url){
	parent.PW.Dialog({
		'id': id,
		'name': name,
		'url': url
	}).loadIframe(url);
}

function changeCheck(id){
	var obj = document.getElementById("checkValue_"+id);
	var v = obj.value;
	if(v==0){
		obj.value=1;
	}else if(v==1){
		obj.value=0;
	}
}
function ckAll(){
	var obj = $(".ck");
	$.each(obj,function(i,val){
		var v = $(val).attr("d");
		$(val).attr("checked","checked");
		$("#checkValue_"+v).attr("value","1");
	});
}
function checkNo(){
	var obj = $(".ck");
	$.each(obj,function(i,val){
		var v = $(val).attr("d");
		$(val).attr("checked",false);
		$("#checkValue_"+v).attr("value","0");
	});
}
</script>

<script type="text/javascript">
var manageclass = {
	superdel : function (obj,forumid,step){
		var form = getObj(forumid);
		form.step.value = step;
		var page = obj.getAttribute("page");
		if(!page){
			page = getObj("input_page").value;
		}
		page = (page) ? page : 1;
		form.page.value = page;
		setTimeout(function(){
			form.submit();
		},0);
	}
}
onReady(function(){
	if(parent.adminNavClass){
		parent.adminNavClass.initTips();
	}
})
</script>
<style type="text/css">
.level1{
	padding-left: 30px;
}
.level2{
	padding-left: 60px;
}
.level3{
	padding-left: 90px;
}
</style>
</head>
<body>

<div class="admin_info mb10">
	<h3 class="h1"><b>提示信息</b></h3>
	<div class="legend" style="color:#E0572A;">★主要功能：为下级开通产品，勾选要开通的产品并设置好价格，保存即可！<br>★提示：如果给下级开通的价格比您自身的价格高，则差额是您的收入，当下级订单完成时这部分收入会以返利形式转至您帐户！</div>
</div>
<form id="dataFormMain" action="" method="post"  onsubmit="return submitForm(this);">
<input type="hidden" name="user.userId" value="${user.userId }"/>    
<div class="admin_table mb10">
<h2 class="h1">为代理【<span style="color:red;text-decoration:underline;font-size:20px;">${user.userAccount }</span>】开通产品(<span style="color:green;"> 操作提示：请勾选要开通的产品 并设置价格</span>)</h2>
<div class="admin_table mb10">
<table cellspacing="0" cellpadding="0" style="width:95%;margin-left:20px;" id="gridTable">
	<!--<thead>
		<tr class="tr2 vt">
            <td width="10">序号</td>
            <td width="50">产品类型</td>
        </tr>
    </thead>-->
	<tbody>
		<tr>
			<td width="70" nowrap style="line-height:32px;"><input type="button" value="全选" onclick="ckAll();" /></td>
			<td width="70" nowrap style="line-height:32px;"><input type="button" value="全不选" onclick="checkNo();" /></td>
		</tr>
		<c:forEach var='item' items='${produceList}' varStatus='u'  step='1'>
        <tr>
        <td>
        	<input type="hidden" name="produceList[${u.index}].id" value="${item.id }"/>
        </td>
        <td width="30" nowrap style="line-height:32px;">${u.index+1}</td>
        <td class="level${item.userBaseIndentType.level }" style="border-bottom:1px dashed #bcbcbc;">
        <input type="hidden" name="produceList[${u.index}].userBaseIndentType.id" value="${item.userBaseIndentType.id }" />
        	<c:if test="${item.isOpen==1 }">
        		 <input class="ck" d="${u.index}" onchange="changeCheck(${u.index})" type="checkbox"  checked/>
        		 <input id="checkValue_${u.index}" type="hidden" name="produceList[${u.index}].isOpen" value="1" />
        	</c:if>
        	<c:if test="${item.isOpen==0 }">
        		 <input class="ck" d="${u.index}" onchange="changeCheck(${u.index})" type="checkbox"  />
        		 <input id="checkValue_${u.index}" type="hidden" name="produceList[${u.index}].isOpen" value="0" />
        	</c:if>
           
            <span style="font-weight:bold;color:green;">${item.userBaseIndentType.baseIndentTypeClassify.name}--${item.userBaseIndentType.name}:</span>
           	<c:if test="${item.hasChild==false }">
           		<c:if test="${item.isOpen==0 }">
           			<input class="input input_wf" style="width:66px" type="text" 
	            		name="produceList[${u.index}].price" 
	            		validate="${item.userBaseIndentType.name }价格||notnull,number"
	            		value="${item.defaultPrice }"/>
           		</c:if>
           		<c:if test="${item.isOpen==1 }">
	           		<input class="input input_wf" style="width:66px" type="text" 
	            		name="produceList[${u.index}].price" 
	            		validate="${item.userBaseIndentType.name }价格||notnull,number"
	            		value="${item.price }"/>
           		</c:if>
           		 
            
            ${item.userBaseIndentType.unit }; ${item.userBaseIndentType.remark }
            
   			 成本价格：
         <sec:authorize ifNotGranted="ROLE_ROOT">
         	${produceList2[u.index].price }
         </sec:authorize>
        <sec:authorize ifAnyGranted="ROLE_ROOT">
         ${produceList3[u.index].price }
         </sec:authorize>
         </c:if>
         </td>
        </tr>
		</c:forEach>
    </tbody>
</table>
</div>
<script type="text/javascript">
  function isIE(){ //ie? 判断是不是ie
     if (window.navigator.userAgent.indexOf("MSIE")>=1)
       return true;
     else
       return false;
    }
   if(!isIE()){
      HTMLElement.prototype.insertAdjacentElement=function(where,parsedNode){
        switch(where){
            case "beforeBegin":
                this.parentNode.insertBefore(parsedNode,this);
                break;
            case "afterBegin":
                this.insertBefore(parsedNode,this.firstChild);
                break;
            case "beforeEnd":
                this.appendChild(parsedNode);
                break;
            case "afterEnd":
                if(this.nextSibling)
                    this.parentNode.insertBefore(parsedNode,this.nextSibling);
                else
                    this.parentNode.appendChild(parsedNode);
                break;
            }
        }
   }
   function checkMenu(obj){
       var needChecked=obj.checked;
       var curTdInputs=obj.parentElement.getElementsByTagName("input");
       var exsitsChecked=false;
       var allChecked=false;
       for(var j=0;j<curTdInputs.length;j++){
           if(curTdInputs[j].checked){
              exsitsChecked=true;;
              break;
           }
       }
       if(!needChecked && exsitsChecked)return false;
       var inputs=obj.parentElement.parentElement.getElementsByTagName("input");
       if(needChecked)//只可选不可取消
       for(var j=0;j<inputs.length;j++){
           if(inputs[j].name && inputs[j].getAttribute("realvalue")){
              if(!inputs[j].checked)inputs[j].click();//.checked=needChecked;
              break;
           }
       }
   }
   function cascadeCheck(obj){
       var needChecked=obj.checked;
       var level=obj.getAttribute("level");
       var rowIndex=obj.parentElement.parentElement.rowIndex;
       var table=obj;
       while(table.parentElement.tagName && table.parentElement.tagName.toLowerCase()!="table"){
           table =table.parentElement
       }
       table =table.parentElement
       if(!table.tagName || table.tagName.toLowerCase()!="table"){
           return;
       }
       for(var i=rowIndex;i<table.rows.length;i++){//向下选择，遇平级止
          var row=table.rows[i];
          var inputs=row.getElementsByTagName("input");
          var checked=false;
          var curRowLevel;
          for(var j=0;j<inputs.length;j++){
             if(inputs[j].name && inputs[j].getAttribute("realvalue")){
                curRowLevel=parseInt(inputs[j].getAttribute("level"));
                if(curRowLevel>level){
                    checked=true;
                    break;
                }
             }
          }
          if(i!=rowIndex && curRowLevel==level){
             break;
          }
          if(checked || i==rowIndex){
            for(var j=0;j<inputs.length;j++){
             if(inputs[j].type=="checkbox"){
                inputs[j].checked=needChecked;
             }
            }
          }
       }
       if(needChecked)//向上只可选择不可取消，原因是如果已经有选择的再取消有冲突
       for(var i=rowIndex;i>0;i--){//向上选择 遇顶级止
          var row=table.rows[i];
          var inputs=row.getElementsByTagName("input");
          var toped=false;
          for(var j=0;j<inputs.length;j++){
              if(inputs[j].name && inputs[j].getAttribute("realvalue")){
               if(parseInt(inputs[j].getAttribute("level"))==1){
                 toped=true;
               }
               if(parseInt(inputs[j].getAttribute("level"))<level){
                  inputs[j].checked=true;
                }
               if(toped)break;
             }
          }
         if(toped)break;
       }
   }
</script>
<div class="tac mb10">
	<span class="btn"><span><button type="button" onclick="doAction('saveAll');">保存</button></span></span>
</div>
<div class="c"></div>
</div>
</form>
<form action="" method="post" id="dataForm"></form>
<script type="text/javascript" src="/etc/system/js/global.js"></script>
<script type="text/javascript" src="/etc/system/js/pw_ajax.js"></script>
<script type="text/javascript" src="/etc/system/js/admin.js"></script>
<script type="text/javascript" src="/etc/system/js/date.js"></script>
<script type="text/javascript" src="/etc/system/js/desktop/plugin.js"></script>
<script type="text/javascript">
function doAction(act){
    if(act=="saveAll"){
        if(!frmSubmit(document.getElementById('dataFormMain'),document.getElementById('gridTable')))return false;
        document.getElementById('dataFormMain').action="produceOpen"
        document.getElementById('dataFormMain').submit();
    }
}

function submitForm(form){
      if(!frmSubmit(form))return false;
      var tplTR=document.getElementById("gridTable").rows[1];
      tplTR.parentElement.removeChild(tplTR);
      return false;
    }
function showConfirm(info,href){
 info = info ;
 showDialog({type:"confirm",message:info,onOk:function(){
   location.href=href;
   return true;
 }});
}
var operations=document.getElementsByTagName("a");
for(var i=0;i<operations.length;i++){
    var obj=operations[i];
    var confirmStr=obj.getAttribute("confirm");
    if(!confirmStr || confirmStr!="yes")continue;
    obj.onclick=function(e){
        e=window.event||e;
        var el=e.srcElement;
        if(!el.getAttribute("confirmurl")){
		   el.setAttribute("confirmurl",el.href);
		   el.href="javascript:void(0);";
		};
        showConfirm("确认执行"+el.innerText+"操作？！",el.getAttribute("confirmurl"));
        return false;
    }
}

var allInputs = document.getElementsByTagName('input');
if(allInputs && allInputs.length>0){
	for(var i=0; i<allInputs.length;i++)
	{
		var ipt = allInputs[i].parentNode;
		if(ipt.tagName=='LI'&& allInputs[i].type=='radio')
		{
			allInputs[i].checked && (ipt.className='current');
			ipt.onclick = function(){radioWithWords(this)};
		}
	}
}
</script>
<script type="text/javascript">
    if (typeof (HTMLElement) != "undefined" && !window.opera) {
    HTMLElement.prototype.__defineGetter__("outerHTML", function () {
        var a = this.attributes, str = "<" + this.tagName, i = 0; for (; i < a.length; i++)
            if (a[i].specified)
                str += " " + a[i].name + '="' + a[i].value + '"';
        if (!this.canHaveChildren)
            return str + " />";
        return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });
    HTMLElement.prototype.__defineSetter__("outerHTML", function (s) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df = r.createContextualFragment(s);
        this.parentNode.replaceChild(df, this);
        return s;
    });
    HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
    });
}
if (typeof (HTMLElement) != "undefined" && !window.opera) {
    HTMLElement.prototype.__defineGetter__("outerHTML", function () {
        var a = this.attributes, str = "<" + this.tagName, i = 0; for (; i < a.length; i++)
            if (a[i].specified)
                str += " " + a[i].name + '="' + a[i].value + '"';
        if (!this.canHaveChildren)
            return str + " />";
        return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });
    HTMLElement.prototype.__defineSetter__("outerHTML", function (s) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df = r.createContextualFragment(s);
        this.parentNode.replaceChild(df, this);
        return s;
    });
    HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
    });
}
</script>
<script type="text/javascript">
    var valueControls={//能直接用 obj.value赋值的控件名及Type
        "input":"text,password,hidden",
        "select":"select-one",
        "textarea":"textarea"
    };
    
    var formData={};
    for(var id in formData){//铺数据
      var obj=document.getElementById(id);
      if(id && obj){//checkBox
        var tagName=obj.tagName.toLowerCase();
        if(obj.type){
          var type=obj.type.toLowerCase();
          if(valueControls[tagName] && valueControls[tagName].indexOf(type)!=-1){
            if(eval("document.getElementById(\""+id+"\")")){
              document.getElementById(id).value=formData[id];
            }
          }else{
             if(type=="radio" || type=="checkbox"){
              initRadioOrCheckBox(id); 
             }
             if(type=="select-multiple"){
              initMultiSelect(id);
             }
          }
        }else{
           obj.innerHTML=formData[id]; 
        }
      }
    }
    function initRadioOrCheckBox(id){
      var servingTimes=document.getElementsByName(id);
      for(var s=0;s<servingTimes.length;s++){
         if(servingTimes[s].type=="checkbox")
           servingTimes[s].checked=false;
      }
      if(formData[id]){
        var servingTimesValue=formData[id].split(",");
        for(var s=0;s<servingTimesValue.length;s++){
         for(var i=0;i<servingTimes.length;i++){
            if(servingTimes[i].value==servingTimesValue[s].trim())
            servingTimes[i].checked=true;
         }
       }
      }else{
       for(var i=0;i<servingTimes.length;i++){
         if(servingTimes[i].type=="checkbox")
           servingTimes[i].checked=true;
       }
      }
   }
   function initMultiSelect(id){
      var selOptions=document.getElementById(id).options;
      for( var i=0;i<selOptions.length;i++){
         selOptions.selected=false;
      }
      if(formData[id]){
        var selOptionsValue=formData[id].split(",");
        for(var s=0;s<selOptionsValue.length;s++){

         for(var i=0;i<selOptions.length;i++){
            if(selOptions[i].value==selOptionsValue[s].trim())
            selOptions[i].selected=true;
         }
       }
      }else{
       for(var i=0;i<selOptions.length;i++){
         selOptions[i].selected=false;
       }
      }
   }
</script>    
<script type="text/javascript">
function getQueryString(form,param) {
        var datastring = '';
        var inputs = form.getElementsByTagName('INPUT');
        for (var i = 0; i < inputs.length; i++) {
            if(inputs[i].name==param)continue;
            
            switch (inputs[i].getAttribute('type')) {
                case 'text':
                    datastring = plamostr(inputs[i], datastring);
                    break;
                case 'hidden':
                    datastring = plamostr(inputs[i], datastring);
                    break;
                case 'checkbox':
                    if (inputs[i].checked) {
                        datastring = plamostr(inputs[i], datastring);
                    }
                    break;
                case 'radio':
                    if (inputs[i].checked) {

                        datastring = plamostr(inputs[i], datastring);
                    }
                    break;
            }
        }
        var textareas = form.getElementsByTagName('TEXTAREA');
        for (var i = 0; i < textareas.length; i++) {
            datastring = plamostr(textareas[i], datastring);
        }
        var selectes = form.getElementsByTagName('SELECT');
        for (var i = 0; i < selectes.length; i++) {
            datastring = plamostr(selectes[i], datastring);
        }
        if(param){
            document.getElementById(param).value=datastring;
        }
        return datastring;
    }
    function plamostr(object, datastring) {
        /**
         *拼装Form数据字符串
         */
        if (datastring.length > 0) {
            datastring += '&' + object.getAttribute('name') + '=' + object.value;
        } else {
            datastring += object.getAttribute('name') + '=' + object.value;
        }
        return datastring;
    }
</script></body></html>

